package com.fr.report.script.core.parser;

import com.fr.report.script.Calculator;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;
import java.math.BigDecimal;

public class UnaryExpression extends AbstractNode
{
  String op;
  Atom atom;

  UnaryExpression(String paramString, Atom paramAtom)
  {
    this.op = paramString;
    this.atom = paramAtom;
  }

  public Object eval(Calculator paramCalculator)
    throws UtilEvalError
  {
    if (this.atom == null)
      throw new InterpreterError("atom should not be null");
    Object localObject = this.atom.eval(paramCalculator);
    if (this.op != null)
      localObject = primitiveWrapperUnaryOperation(localObject, this.op);
    return localObject;
  }

  private Object primitiveWrapperUnaryOperation(Object paramObject, String paramString)
    throws UtilEvalError
  {
    if ((paramObject == Primitive.ERROR_NAME) || (paramObject == Primitive.ERROR_NAME))
      return Primitive.ERROR_NAME;
    if (paramObject instanceof FArray)
    {
      localObject = (FArray)paramObject;
      Object[] arrayOfObject = new Object[((FArray)localObject).length()];
      for (int i = 0; i < arrayOfObject.length; ++i)
        arrayOfObject[i] = primitiveWrapperUnaryOperation(((FArray)localObject).elementAt(i), paramString);
      return new FArray(arrayOfObject);
    }
    Object localObject = OperationUtils.promoteCharByteShort(paramObject);
    if (localObject instanceof Boolean)
      return new Boolean(OperationUtils.booleanUnaryOperation((Boolean)localObject, paramString));
    if (localObject instanceof Integer)
      return new Integer(OperationUtils.intUnaryOperation((Integer)localObject, paramString));
    if (localObject instanceof Long)
      return new Long(OperationUtils.longUnaryOperation((Long)localObject, paramString));
    if (localObject instanceof Float)
      return new Float(OperationUtils.floatUnaryOperation((Float)localObject, paramString));
    if (localObject instanceof Double)
      return new Double(OperationUtils.doubleUnaryOperation((Double)localObject, paramString));
    if (localObject instanceof BigDecimal)
      return OperationUtils.bigDecimalUnaryOperation((BigDecimal)localObject, paramString);
    throw new InterpreterError("error exists: " + paramString + this.atom);
  }

  public void traversal4Tiny(TinyHunter paramTinyHunter)
  {
    this.atom.traversal4Tiny(paramTinyHunter);
  }

  public String exString(Calculator paramCalculator)
  {
    return ((this.op != null) ? this.op : "") + this.atom.exString(paramCalculator);
  }

  public String toString()
  {
    return ((this.op != null) ? this.op : "") + this.atom.toString();
  }

  public String getExpression(int paramInt1, int paramInt2, int paramInt3, int paramInt4, boolean paramBoolean)
  {
    return ((this.op != null) ? this.op : "") + this.atom.getExpression(paramInt1, paramInt2, paramInt3, paramInt4, paramBoolean);
  }

  public String[] parserParameter()
  {
    return this.atom.parserParameter();
  }
}